#include "CubeBox.hpp"
CubeBox::CubeBox(){}
CubeBox::CubeBox(float s, QVector3D c)
{
	vertices = {c.x()+s, c.y()+s, c.z()+s, //0
				c.x()+s, c.y()+s, c.z()-s, //1
				c.x()+s, c.y()-s, c.z()-s, //2
				c.x()+s, c.y()-s, c.z()+s, //3
				c.x()-s, c.y()+s, c.z()+s, //4
				c.x()-s, c.y()+s, c.z()-s, //5
				c.x()-s, c.y()-s, c.z()-s, //6
				c.x()-s, c.y()-s, c.z()+s}; //7

    indices = { 0, 2, 3,
                0, 1, 2,
                1, 5, 2,
                5, 6, 2,
                5, 4, 6,
                4, 7, 6,
                4, 1, 0,
                4, 5, 1,
                7, 3, 6,
                3, 2, 6};
    colors = {   0.8, 0.4, 0.2,
                 0.8, 0.4, 0.2,

                 0.8, 0.8, 0.8,
                 0.8, 0.8, 0.8,

                 0.0, 0.2, 0.8,
                 0.0, 0.2, 0.8,


                 0.8, 0.8, 0.8,
                 0.8, 0.8, 0.8,

                 0.8, 0.8, 0.8,
                 0.8, 0.8, 0.8};
    normales = { -1.0,  0.0,  0.0,
                 -1.0,  0.0,  0.0,
                  0.0,  0.0,  1.0,
                  0.0,  0.0,  1.0,
                  1.0,  0.0,  0.0,
                  1.0,  0.0,  0.0,
                  0.0, -1.0,  0.0,
                  0.0, -1.0,  0.0,
                  0.0,  1.0,  0.0,
                  0.0,  1.0,  0.0 };
    //normales = n;
    color1 = {1.0, 0.4, 0.2};
    color2 = {0.2, 1, 0.4};
    defaultColor = {1, 1, 1};
}

#include <QtOpenGL>
#include <iostream>
using namespace std;
void CubeBox::drawCubeBox(){
    glBegin(GL_TRIANGLES);
    for (int i = 0; i < CUBEBOX_NB_POLY; ++i)
    {
        int i1 = getIndices()[i*3];
        int i2 = getIndices()[i*3+1];
        int i3 = getIndices()[i*3+2];
        if (i == 0 || i == 1)
            glColor3f(color1[0], color1[1], color1[2]);
        else if (i == 4 || i == 5)
            glColor3f(color2[0], color2[1], color2[2]);
        else
            glColor3f(defaultColor[0], defaultColor[1], defaultColor[2]);

        glNormal3f(normales[i*3],
                   normales[i*3+1],
                   normales[i*3+2]);
        glVertex3f(vertices[i1*3],
                   vertices[i1*3+1],
                   vertices[i1*3+2]);

        glNormal3f(normales[i*3],
                   normales[i*3+1],
                   normales[i*3+2]);
        glVertex3f(vertices[i2*3],
                   vertices[i2*3+1],
                   vertices[i2*3+2]);

        glNormal3f(normales[i*3],
                   normales[i*3+1],
                   normales[i*3+2]);
        glVertex3f(vertices[i3*3],
                   vertices[i3*3+1],
                   vertices[i3*3+2]);
    }
    glEnd();
}

void CubeBox::setColor1(float r, float g, float b)
{
    color1[0] = r;
    color1[1] = g;
    color1[2] = b;
}
void CubeBox::setColor2(float r, float g, float b)
{
    color2[0] = r;
    color2[1] = g;
    color2[2] = b;
}
void CubeBox::setDefaultColor(float r, float g, float b)
{
    defaultColor[0] = r;
    defaultColor[1] = g;
    defaultColor[2] = b;
}
